import java.util.*;

public class Test {

    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for(String s2 : tokens) {
            if(!isOperations(s2)) {
                stack.push(Integer.parseInt(s2));
            }else {
                int num2 = stack.pop();
                int num1 = stack.pop();
                switch (s2) {
                    case "+":
                        stack.push(num1 + num2);
                        break;
                    case "-":
                        stack.push(num1 - num2);
                        break;
                    case "*":
                        stack.push(num1 * num2);
                        break;
                    case "/":
                        stack.push(num1 / num2);
                        break;
                }
            }
        }
        return stack.pop();
    }


    private boolean isOperations(String oper) {
        if(oper.equals("+") || oper.equals("-") || oper.equals("*")){
            return true;
        }
        return false;
    }

    public boolean isValid(String s) {

        Stack<Character> stack = new Stack<>();

        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(ch == '(' || ch == '[' || ch == '{') {
                stack.push(ch);
            }else {
                if(stack.empty()) {
                    return false;
                }
                char ch2 = stack.peek();
                if(ch2 == '(' && ch == ')' || ch2 == '[' && ch == ']'
                        || ch2 == '{' && ch == '}' ) {
                    stack.pop();
                }else {
                    return false;
                }
            }
        }
        if(!stack.empty()) {
            return false;
        }
        return true;
    }

    public boolean IsPopOrder(int[] pushV,int[] popV) {
        Stack<Integer> stack = new Stack<>();
        int j = 0;
        int i = 0;
        for(;i < pushV.length; i++) {
            stack.push(pushV[i]);
            while(!stack.empty() && j < popV.length && stack.peek() == popV[i]) {
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        MyStack myStack = new MyStack();
        myStack.push(12);
        myStack.push(23);
        myStack.push(34);
        myStack.push(45);

        System.out.println(myStack.pop());//45
        System.out.println(myStack.peek());//34
        System.out.println(myStack.size());//3
        System.out.println(myStack.isEmpty());

        LinkedList<Integer> stack = new LinkedList<>();
    }

    public static void main3(String[] args) {
        Stack<Integer> stack = new Stack<>();
        stack.push(12);
        stack.push(24);
        stack.push(34);
        stack.push(45);

        System.out.println(stack.pop());
        System.out.println(stack.peek());
        System.out.println(stack.peek());
    }

    public static void main2(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);

        //打印链表法一
        System.out.println(list);
        System.out.println("===================");

        //法二
        for(int i = 0; i < list.size(); i++) {
            System.out.print(list.get(i)+" ");
        }
        System.out.println();
        System.out.println("===================");

        //法三
        for (int x: list) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println("===================");

        //法四
        Iterator<Integer> it = list.iterator();
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        System.out.println("===================");

        //法五
        ListIterator<Integer> lit = list.listIterator();
        while(lit.hasNext()) {
            System.out.print(lit.next()+" ");
        }
        System.out.println();
        System.out.println("===================");

        //法六
        ListIterator<Integer> lit2 = list.listIterator(list.size());
            while(lit2.hasPrevious()) {
                System.out.print(lit2.previous()+"");
            }
        System.out.println();
        }


    public static void main1(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        //默认为头插
        list.add(1);
        list.add(2);
        list.add(0,3);

        System.out.println(list);

        List<Integer> list1 = new ArrayList<>();
        list1.add(10);
        list1.add(20);
        list1.add(30);

        list.addAll(list1);

        System.out.println(list);

        list.clear();

    }
}





